package com.lyn.solitude.pluginhost.handler.andserver

import android.text.TextUtils
import android.util.Log
import com.lyn.solitude.pluginhost.andserver.RequestMethod
import com.lyn.solitude.pluginhost.andserver.interceptor.Interceptor
import org.apache.httpcore.HttpRequest
import org.apache.httpcore.HttpResponse
import org.apache.httpcore.protocol.HttpContext

/**
 *
 * @author longyn 2024/05/28
 * @version 1.0.0
 */
class AndServerInterceptor : Interceptor {

    companion object{
        const val TAG = "AndServerInterceptor"
    }
    override fun onBeforeExecute(
        request: HttpRequest,
        response: HttpResponse,
        context: HttpContext
    ): Boolean {
        val entries = RequestMethod.entries
        val join = TextUtils.join(",", entries)
        response.setHeader("Access-Control-Allow-Origin", "*")
        response.setHeader("Access-Control-Allow-Methods", join)
        response.setHeader("Access-Control-Allow-Headers", "*")
        response.setHeader("Access-Control-Allow-Credentials", "true")
        response.setHeader("Access-Control-Max-Age", "3600")
        response.setHeader("Allow", join)
        return false
    }

    override fun onAfterExecute(
        request: HttpRequest?,
        response: HttpResponse?,
        context: HttpContext?
    ) {

    }
}